package cn.lg.soar.message.feign.fallback;

import cn.lg.soar.message.api.model.WebSocketDTO;
import cn.lg.soar.message.feign.SseApiFeign;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.cloud.openfeign.FallbackFactory;

import java.util.ArrayList;
import java.util.Collection;

/**
 * @author luguoxiang
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
@ConditionalOnMissingClass("cn.lg.soar.message.client.SseApiClient")
public class SseApiFallbackFactory implements FallbackFactory<SseApiFeign> {

    private static final Logger LOGGER = LoggerFactory.getLogger(SseApiFallbackFactory.class);

    @Override
    public SseApiFeign create(Throwable cause) {
        return new SseApiFeign() {
            @Override
            public Collection<Long> broadcast(String topic, String message) {
                LOGGER.error("broadcast：topic={}，message={}", topic, message, cause);
                return new ArrayList<>(0);
            }

            @Override
            public Collection<Long> sendMessage(String topic, WebSocketDTO dto) {
                LOGGER.error("sendMessage：topic={}，dto={}", topic, dto, cause);
                return new ArrayList<>(0);
            }
        };
    }
}
